package xjtu.sad.zbsj.statistics.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import xjtu.sad.zbsj.statistics.Historys;
import xjtu.sad.zbsj.statistics.StatisticsDto;
import xjtu.sad.zbsj.statistics.WithdrawHistory;

import java.util.List;

public interface StatisticsDao {

    @Update("update t_credit set total_credit=total_credit-#{money} where user_id =#{user_id}")
    void withdrawMoney(StatisticsDto statisticsDto);

    @Select("select total_credit from t_credit where user_id = #{user_id}")
    String getCredit(String user_id);

    @Select("select end_time from t_draw  where end_time between concat(#{year},'-01-01') and concat(#{year},'-12-31') and user_id=#{user_id} and draw_status != 'WWC' order by end_time desc")
    List<String> selectTaskNums(String user_id,String year);
    @Select("select start_time from t_draw  where start_time between concat(#{year},'-01-01') and concat(#{year},'-12-31') and user_id=#{user_id} order by start_time desc")
    List<String> selectTaskSNums(String user_id,String year);
    @Select("SELECT round(credit/task_award,2)*100 FROM credit_view where user_id=#{user_id} and end_time is not null order by end_time asc limit 10")
    List<Float> selectRightRate(String user_id);

    @Select("select round(sum(credit/task_award)/count(*),4)*100 from credit_view where user_id  =#{user_id} and end_time is not null")
    float selectTotalRightRate(String user_id);

    @Select("select count(end_time) from credit_view where user_id = #{user_id}")
    int getCount(String user_id);


    @Select("select * from t_withdraw_history where user_id = #{user_id} order by withdraw_time desc")
    List<WithdrawHistory> getHistory(String user_id);

    @Insert("insert into t_withdraw_history values(#{withdraw_id},#{user_id},#{withdraw_time},#{money}) ")
    void record(StatisticsDto statisticsDto);

    @Select("select withdraw_id from t_withdraw_history order by withdraw_id desc limit 1")
    int getWithdraw_id();
}
